package com.example.demo.mapper;

import com.example.demo.mapper.entity.Attribute;
import com.example.demo.mapper.entity.StudentAttribute;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Lucy
 * @create 2024-02-13 16:24
 */
@Mapper
@Repository
public interface StudentAttributeMapper {
    @Select("SELECT * FROM attribute")
    List<Attribute> selectAllAttribute();
    @Insert("INSERT INTO student_attribute(student_id, attribute_id) " +
            "   VALUES(#{studentId}, #{attributeId})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertStudentAttribute(StudentAttribute studentAttribute);
    @Select("SELECT * FROM student_attribute WHERE student_id = #{studentId}")
    List<StudentAttribute> getStudentAttributeList(int studentId);

    @Select("SELECT * FROM attribute WHERE attribute_id = #{attributeId}")
    Attribute selectAttributeById(int attributeId);
    @Select("SELECT * FROM attribute LIMIT 4")
    List<Attribute> selectAttribute4();
    @Select("SELECT * FROM attribute WHERE name = #{attributeName}")
    Attribute selectAttributeByName(String attributeName);
    @Update("UPDATE student_attribute SET value = value + #{value} WHERE student_id = #{studentId} AND attribute_id = #{attributeId}")
    void updateStudentAttribute(@Param("studentId") int studentId, @Param("attributeId") Integer attributeId, @Param("value") Integer value);
}
